var topic_index_ops={
    init:function(){
        this.eventBind();
    },

    eventBind:function(){

        //删除专题
        $('.delete').click(function(){
            var id=$(this).attr('opt-id');
            var title=$(this).attr('data-title');

            var callback={
                ok:function(){
                    topic_index_ops.send(id,'delete');
                }
            };

            common_ops.confirm('确认删除 <b>'+title+'</b> 专题?',callback);
        });

        //恢复专题
        $('.recover').click(function(){
            var id=$(this).attr('opt-id');
            var title=$(this).attr('data-title');

            var callback={
                ok:function(){
                    topic_index_ops.send(id,'recover');
                }
            };

            common_ops.confirm('确认恢复 <b>'+title+'</b> 专题?',callback);
        })
    },

    send:function(id,opt){
        $.ajax({
            url:'/admin/topics/opt',
            type:'post',
            data:{
                id:id,
                opt:opt
            },
            dataType:'json',
            success:function(res){
                var callback=null;

                if(res.code == 200){
                    callback=function(){
                        window.location.href=window.location.href;
                    }
                }

                common_ops.alert(res.msg,callback);
            }
        });
    }
};

$(document).ready(function(){
    topic_index_ops.init();
});